home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Arsenal / OS2 Arsenal v1.0 (Disc 1)(Arsenal Computer).ISO / os2_inet / tcp20c2.exe / BASEC2.ZIP / BIN / direct.cmd < prev    next >
Encoding:
Text File  |  1994-05-03  |  8.1 KB  |  205 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                OS/2 2.0 SLIP Driver for IBM TCP/IP version 2.0           */
  4. /*                                                                          */
  5. /*                                DIRECT.CMD                                */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for direct connection between to asynchronous   */
  10. /* lines.  This script should be specified using                            */
  11. /* the "attachcmd" and "attachparm" elements in the configuration file.     */
  12. /* For example:                                                             */
  13. /*                                                                          */
  14. /*              interface sl0 {                                             */
  15. /*                 attachcmd  = direct                                      */
  16. /*              }                                                           */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /* When the script runs, it is automatically passed the interface name for  */
  20. /* the interface it is running on as the first argument, and the user       */
  21. /* arguments (from the configuration file) as the remaining parameters.     */
  22. /*--------------------------------------------------------------------------*/
  23.  
  24. parse arg interface , ipaddress, ipdest, comport baud
  25.  
  26. /* Setup modem for autoanswer mode */
  27. /* check for input arg */
  28.  
  29. say ''
  30. say 'DIRECT - SL/IP NULL Modem Connection script',
  31.     '(interface' interface')'
  32.  
  33. /* Set some definitions for easier COM strings */
  34. cr='0d'x
  35. crlf='0d0a'x
  36.  
  37. /* check input args and take default if not specified in DIRECT.CFG */
  38. if interface='' | interface='*' then do
  39.    call lineout , ' DIRECT: INTERFACE not specified.  Default SL0 '
  40.    interface='sl0'
  41.   end
  42.  
  43. if comport= '' | comport='*' then do
  44.    call lineout , ' DIRECT: COM Port was not specified.  Default COM1 '
  45.    comport='COM1'
  46.   end
  47.  
  48. if baud='' | baud='*' then do
  49.    call lineout , ' DIRECT: BAUD was not specified.  Default 38400 '
  50.    baud='38400'
  51.   end
  52.  
  53. if ipaddress='' | ipaddress='*' then do
  54.    ipaddress='222.222.222.10'
  55.    call lineout , ' DIRECT: IPADDRESS was not specified.  Default ' ipaddress
  56.   end
  57.  
  58. if ipdest='' | ipdest='*' then do
  59.    ipdest='222.222.222.20'
  60.    call lineout , ' DIRECT: IPDEST was not specified.  Default ' ipdest
  61.   end
  62.  
  63. /* Setup TCPIP info for this machine */
  64. call lineout , ' DIRECT: Setting up TCPIP info for this machine ...'
  65.  
  66. /*
  67.  * Comment or Uncomment as appropriate for your configuration
  68.  */
  69. /* 'arp -f' */
  70.  
  71. 'ifconfig ' interface ipaddress ipdest ' netmask 255.255.240.0'
  72.  
  73. /* 'route add default ' ipdest '1' */
  74.  
  75. /* Setup COM Port */
  76. call lineout , ' DIRECT: COM Port settings: mode 'comport baud',n,8,1'
  77. 'mode 'comport baud',n,8,1,BUFFER=ON'
  78.  
  79. /*--------------------------------------------------------------------------*/
  80. /*                   Initialization and Main Script Code                    */
  81. /*--------------------------------------------------------------------------*/
  82.  
  83.  
  84. /* Flush any stuff left over from previous COM activity */
  85. call flush_receive
  86.  
  87. /* Setup All done, returning control to SLIP */
  88. exit 0
  89.  
  90.  
  91. /*--------------------------------------------------------------------------*/
  92. /*                            send ( sendstring)                            */
  93. /*..........................................................................*/
  94. /*                                                                          */
  95. /* Routine to send a character string off to the modem.                     */
  96. /*                                                                          */
  97. /*--------------------------------------------------------------------------*/
  98.  
  99. send:
  100.  
  101.    parse arg sendstring
  102.    call slip_com_output interface , sendstring
  103.  
  104.    return
  105.  
  106. /*--------------------------------------------------------------------------*/
  107. /*                    waitfor ( waitstring , [timeout] )                    */
  108. /*..........................................................................*/
  109. /*                                                                          */
  110. /* Waits for the supplied string to show up in the COM input.  All input    */
  111. /* from the time this function is called until the string shows up in the   */
  112. /* input is accumulated in the "waitfor_buffer" variable.                   */
  113. /*                                                                          */
  114. /* If timeout is specified, it says how long to wait if data stops showing  */
  115. /* up on the COM port.                                                      */
  116. /*                                                                          */
  117. /*--------------------------------------------------------------------------*/
  118.  
  119. waitfor:
  120.  
  121.    parse arg waitstring , timeout
  122.  
  123.    waitfor_buffer = '' ; done = 0 ; curpos = 1
  124.  
  125.    if (remain_buffer = 'REMAIN_BUFFER') then do
  126.       remain_buffer = ''
  127.    end
  128.  
  129.    do while done = 0
  130.       if (remain_buffer \= '') then do
  131.          line = remain_buffer
  132.          remain_buffer = ''
  133.       end
  134.       else do
  135.          line = slip_com_input(interface)
  136.       end
  137.       waitfor_buffer = waitfor_buffer || line
  138.       index = pos(waitstring,waitfor_buffer)
  139.       if (index > 0) then do
  140.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  141.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  142.          done = 1
  143.       end
  144.       call charout , substr(waitfor_buffer,curpos)
  145.       curpos = length(waitfor_buffer)+1
  146.     end
  147.  
  148.   return
  149.  
  150.  
  151. /*--------------------------------------------------------------------------*/
  152. /*                               readpass ()                                */
  153. /*..........................................................................*/
  154. /*                                                                          */
  155. /* Routine used to read a password from the user without echoing the        */
  156. /* password to the screen.                                                  */
  157. /*                                                                          */
  158. /*--------------------------------------------------------------------------*/
  159.  
  160. readpass:
  161.  
  162.   answer = ''
  163.   do until key = cr
  164.     key = slip_getch()
  165.     if key \= cr then do
  166.       answer = answer || key
  167.     end
  168.   end
  169.   say ''
  170.   return answer
  171.  
  172.  
  173. /*--------------------------------------------------------------------------*/
  174. /*                             flush_receive ()                             */
  175. /*..........................................................................*/
  176. /*                                                                          */
  177. /* Routine to flush any pending characters to be read from the COM port.    */
  178. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  179. /* point it returns.                                                        */
  180. /*                                                                          */
  181. /* The optional echo argument, if 1, says to echo flushed information.      */
  182. /*                                                                          */
  183. /*--------------------------------------------------------------------------*/
  184.  
  185. flush_receive:
  186.  
  187.    parse arg echo
  188.  
  189.    /* If echoing the flush - take care of waitfor remaining buffer */
  190.    if (echo \= '') & (length(remain_buffer) > 0) then do
  191.       call charout , remain_buffer
  192.       remain_buffer = ''
  193.    end
  194.  
  195.    /* Eat anything left in the modem or COM buffers */
  196.    /* Stop when nothing new appears for 100ms.      */
  197.  
  198.    do until line = ''
  199.      line = slip_com_input(interface,,100)
  200.      if echo \= '' then
  201.         call charout , line
  202.    end
  203.  
  204.    return
  205.